#include <iostream>

int const maxn = 10002;
int const maxm = 502;
int da[maxn];
int f[maxn][maxm];

int n, m;

int main()
{
	std::cin >> n >> m;
	for (int i = 0; i < n; i++) std::cin >> da[i];

	f[0][0] = 0;  f[0][1] = da[0];  f[1][0] = da[0];
	for (int i = 1; i < n; i++) {
		f[i][0] = std::max(f[i][0], f[i-1][0]);
		for (int j = 1; j <= m; j++) {
			if (f[i-1][j-1] + da[i] > f[i][j]) {
				f[i][j] = f[i-1][j-1] + da[i];
				if (i+j <= n-1) f[i+j][0] = std::max(f[i+j][0], f[i][j]);
			}
		}
	}
	std::cout << f[n-1][0] << "\n";
}

